<template>
  <div>
    <el-dialog title="分配员工角色" :visible="isShowRole" @close="btnCancel">
      <el-checkbox-group v-model="RoleIds">
        <el-checkbox v-for="item in RoleList" :key="item.id" :label="item.id">{{ item.name }}</el-checkbox>
      </el-checkbox-group>
      <template #footer>
        <el-button @click="btnOk">确定</el-button>
        <el-button @click="btnCancel">取消</el-button>
      </template>
    </el-dialog>
  </div>
</template>

<script>
import { getRoleList } from '@/api/setting'
import { getUserByid } from '@/api/user'
import { assignRoles } from '@/api/employees'
export default {
  props: {
    isShowRole: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      RoleList: [],
      RoleIds: [],
      emloyeId: ''
    }
  },
  created() {
    this.getRoleList()
  },
  methods: {
    async getRoleList() {
      const { rows } = await getRoleList({ page: 1, pageSize: 999 })
      this.RoleList = rows
    },
    async getRoleId(emloyessId) {
      this.emloyeId = emloyessId
      const { roleIds } = await getUserByid(emloyessId)
      this.RoleIds = roleIds
    },
    async btnOk() {
      await assignRoles({
        id: this.emloyeId,
        roleIds: this.RoleIds
      })
      this.$message.success('新增成功')
      this.$emit('assignRoles')
    },
    async btnCancel() {
      this.RoleIds = []
      this.$emit('assignRoles')
    }
  }
}
</script>

<style>

</style>
